﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.ComponentModel.DataAnnotations;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using nERP.Model.Wms;
using nERP.Model;
using nERP.Model.Bas;

namespace nERP.ViewModel.Wms.OtherOutWarehouseDetailVMs
{
    public partial class OtherOutWarehouseDetailListVM : BasePagedListVM<OtherOutWarehouseDetail_View, OtherOutWarehouseDetailSearcher>
    {
        
        protected override IEnumerable<IGridColumn<OtherOutWarehouseDetail_View>> InitGridHeader()
        {
            return new List<GridColumn<OtherOutWarehouseDetail_View>>{
                
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_Seq).SetTitle(@Localizer["Page.序号"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_OtherOutWarehouse).SetTitle(@Localizer["Page.其他出库"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_OtherOutWarehouseDetailCode).SetTitle(@Localizer["Page.出库明细单号"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_Warehouse).SetTitle(@Localizer["Page.仓库"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_Goods).SetTitle(@Localizer["Page.商品"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_GoodsName).SetTitle(@Localizer["Page.商品名称"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_GoodsSpec).SetTitle(@Localizer["Page.商品规格"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_GoodsUnit).SetTitle(@Localizer["Page.计量单位"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_OtherOutNumber).SetTitle(@Localizer["Page.出库数量"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_Remark).SetTitle(@Localizer["_Admin.Remark"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_Status).SetTitle(@Localizer["Page.状态"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_CreateTime).SetTitle(@Localizer["_Admin.CreateTime"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_UpdateTime).SetTitle(@Localizer["_Admin.UpdateTime"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_CreateBy).SetTitle(@Localizer["_Admin.CreateBy"].Value),
                this.MakeGridHeader(x => x.OtherOutWarehouseDetail_UpdateBy).SetTitle(@Localizer["_Admin.UpdateBy"].Value),

                this.MakeGridHeaderAction(width: 200)
            };
        }

        
        public override IOrderedQueryable<OtherOutWarehouseDetail_View> GetSearchQuery()
        {
            var query = DC.Set<OtherOutWarehouseDetail>()
                
                .CheckEqual(Searcher.Seq, x=>x.Seq)
                .CheckEqual(Searcher.OtherOutWarehouseId, x=>x.OtherOutWarehouseId)
                .CheckContain(Searcher.OtherOutWarehouseDetailCode, x=>x.OtherOutWarehouseDetailCode)
                .CheckEqual(Searcher.WarehouseId, x=>x.WarehouseId)
                .CheckEqual(Searcher.GoodsId, x=>x.GoodsId)
                .CheckContain(Searcher.GoodsName, x=>x.GoodsName)
                .CheckContain(Searcher.GoodsSpec, x=>x.GoodsSpec)
                .CheckContain(Searcher.GoodsUnit, x=>x.GoodsUnit)
                .CheckEqual(Searcher.OtherOutNumber, x=>x.OtherOutNumber)
                .CheckContain(Searcher.Remark, x=>x.Remark)
                .CheckEqual(Searcher.Status, x => x.Status)
                .CheckBetween(Searcher.CreateTime?.GetStartTime(), Searcher.CreateTime?.GetEndTime(), x => x.CreateTime, includeMax: false)
                .CheckBetween(Searcher.UpdateTime?.GetStartTime(), Searcher.UpdateTime?.GetEndTime(), x => x.UpdateTime, includeMax: false)
                .CheckContain(Searcher.CreateBy, x=>x.CreateBy)
                .CheckContain(Searcher.UpdateBy, x=>x.UpdateBy)
                .Select(x => new OtherOutWarehouseDetail_View
                {
				    ID = x.ID,
                    
                    OtherOutWarehouseDetail_Seq = x.Seq,
                    OtherOutWarehouseDetail_OtherOutWarehouse = DC.Set<OtherOutWarehouse>().Where(z0 => z0.OtherOutWarehouseCode == x.OtherOutWarehouseId).Select(y => y.OtherOutWarehouseCode).FirstOrDefault(),
                    OtherOutWarehouseDetail_OtherOutWarehouseDetailCode = x.OtherOutWarehouseDetailCode,
                    OtherOutWarehouseDetail_Warehouse = DC.Set<Warehouse>().Where(z0 => z0.WarehouseCode == x.WarehouseId).Select(y => y.WarehouseName).FirstOrDefault(),
                    OtherOutWarehouseDetail_Goods = x.GoodsId,// DC.Set<Goods>().Where(z0 => z0.GoodsCode == x.GoodsId).Select(y => y.GoodsName).FirstOrDefault(),
                    OtherOutWarehouseDetail_GoodsName = x.GoodsName,
                    OtherOutWarehouseDetail_GoodsSpec = x.GoodsSpec,
                    OtherOutWarehouseDetail_GoodsUnit = x.GoodsUnit,
                    OtherOutWarehouseDetail_OtherOutNumber = x.OtherOutNumber,
                    OtherOutWarehouseDetail_Remark = x.Remark,
                    OtherOutWarehouseDetail_Status = x.Status,
                    OtherOutWarehouseDetail_CreateTime = x.CreateTime,
                    OtherOutWarehouseDetail_UpdateTime = x.UpdateTime,
                    OtherOutWarehouseDetail_CreateBy = x.CreateBy,
                    OtherOutWarehouseDetail_UpdateBy = x.UpdateBy,
                })
                .OrderBy(x => x.ID);
            return query;
        }

        
    }
    public class OtherOutWarehouseDetail_View: OtherOutWarehouseDetail
    {
        
        public int? OtherOutWarehouseDetail_Seq { get; set; }
        public string OtherOutWarehouseDetail_OtherOutWarehouse { get; set; }
        public string OtherOutWarehouseDetail_OtherOutWarehouseDetailCode { get; set; }
        public string OtherOutWarehouseDetail_Warehouse { get; set; }
        public string OtherOutWarehouseDetail_Goods { get; set; }
        public string OtherOutWarehouseDetail_GoodsName { get; set; }
        public string OtherOutWarehouseDetail_GoodsSpec { get; set; }
        public string OtherOutWarehouseDetail_GoodsUnit { get; set; }
        public decimal? OtherOutWarehouseDetail_OtherOutNumber { get; set; }
        public string OtherOutWarehouseDetail_Remark { get; set; }
        public dStatusTypeEnum? OtherOutWarehouseDetail_Status { get; set; }
        public DateTime? OtherOutWarehouseDetail_CreateTime { get; set; }
        public DateTime? OtherOutWarehouseDetail_UpdateTime { get; set; }
        public string OtherOutWarehouseDetail_CreateBy { get; set; }
        public string OtherOutWarehouseDetail_UpdateBy { get; set; }

    }

}